using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;
using Pay.TO;
using System;

namespace Pay.Service.AutoMapper {
    public class AuthInfoMapper : IStartupDto {
        private IMapperConfigurationExpression _cfg;
        public AuthInfoMapper(IMapperConfigurationExpression cfg) {
            _cfg = cfg;
        }
        public void Execute() {
            Create();
        }
        protected virtual void Create() {
            _cfg.CreateMap<AuthInfo, authinfo_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
                .ForMember(dest => dest.order_no, src => src.MapFrom(c => c.OrderNo))
                .ForMember(dest => dest.bank_name, src => src.MapFrom(c => c.BankName))
                .ForMember(dest => dest.account_no, src => src.MapFrom(c => c.AccountNo))
                .ForMember(dest => dest.certificate_type, src => src.MapFrom(c => c.CertificateType))
                .ForMember(dest => dest.account_name, src => src.MapFrom(c => c.AccountName))
                .ForMember(dest => dest.id_card, src => src.MapFrom(c => c.IdCard))
                .ForMember(dest => dest.card_img, src => src.MapFrom(c => c.CardImg))
                .ForMember(dest => dest.pay_channel, src => src.MapFrom(c => c.PayChannel))
                .ForMember(dest => dest.certificate_type, src => src.MapFrom(c => c.CertificateType))
                .ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()))
                .ForMember(dest => dest.merchant, src => src.MapFrom(c => c.Merchant))
                .ForMember(dest => dest.amount, src => src.MapFrom(c => c.Amount))
                .ForMember(dest => dest.audit_time, src => src.MapFrom(c => (c.AuditTime == null ? (DateTime?)null : ((long)c.AuditTime).ToDateTime())))
                .ForMember(dest => dest.audit_user_mobile, src => src.MapFrom(c => c.AuditUserMobile));

            _cfg.CreateMap<AuthInfo, authinfo_req>()
                .ForMember(dest => dest.account_name, src => src.MapFrom(c => c.AccountName))
                .ForMember(dest => dest.id_card, src => src.MapFrom(c => c.IdCard))
                .ForMember(dest => dest.card_img, src => src.MapFrom(c => c.CardImg))
                .ForMember(dest => dest.certificate_type, src => src.MapFrom(c => c.CertificateType));

            _cfg.CreateMap<authinfo_dto, authinfo_req>();
        }
    }
}
